local lanjiao = fk.CreateSkill{
  name = "rfenghou_3d17j__lanjiao",
  tags = { Skill.Switch, Skill.Compulsory }
}

Fk:addQmlMark{
  name = "rfenghou_3d17j__lanjiao",
  how_to_show = function(name, value, player)
    if type(value) ~= "table" then
      return " "
    end
    local arr = value.all
    local pos = math.max(math.min(value.pos, #arr), 1)
    local str = Fk:translate(arr[pos]) or ""
    if arr[pos - 1] then
      -- str = Fk:translate(arr[pos - 1]) .. "-" .. str
      -- if arr[pos - 2] then
        str = "...|" .. str
      -- end
    end
    if arr[pos + 1] then
      -- str = str .. "-" .. Fk:translate(arr[pos + 1])
      -- if arr[pos + 2] then
        str = str .. "|..."
      -- end
    end
    if value.pos > #arr then
      str = str .. "|＞"
    elseif value.pos < 1 then
      str = "＜|" .. str
    end
    return str
  end,
  qml_path = "packages/aaa_Romantic/qml/LanJiaoBox"
}

lanjiao:addLoseEffect(function (self, player, is_death)
  local mark = player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao")
  local general = player:getMark("@rfenghou_3d17j__lanjiao")
  if general ~= 0 then
    local skills = table.map(Fk.generals[general]:getSkillNameList(), function(s) return "-" .. s end)
    player.room:handleAddLoseSkills(player, skills)
    player.room:setPlayerMark(player, "@rfenghou_3d17j__lanjiao", 0)
  end
  if mark ~= 0 then
    player.room:returnToGeneralPile(mark.all)
  end
  player.room:setPlayerMark(player, "@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao", 0)
end)

lanjiao:addEffect(fk.GameStart, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(lanjiao.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local generals = room:findGenerals(function(name)
      local g = Fk.generals[name]
      return g.gender == General.Female
    end, player.maxHp)
    room:setPlayerMark(player, "@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao", { all = generals, pos = player:getLostHp() })
  end
})
lanjiao:addEffect(fk.HpChanged, {
  is_delay_effect = true,
  mute = true,
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao")
    mark.pos = player:getLostHp()
    player.room:setPlayerMark(player, "@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao", mark)
  end
})
lanjiao:addEffect(fk.MaxHpChanged, {
  is_delay_effect = true,
  mute = true,
  can_refresh = function (self, event, target, player, data)
    return player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao")
    mark.pos = player:getLostHp()
    player.room:setPlayerMark(player, "@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao", mark)
  end
})

lanjiao:addEffect(fk.TurnStart, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(lanjiao.name) and player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local mark = player:getMark("@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao")
    local bias = 1 - player:getSwitchSkillState(lanjiao.name, false) * 2
    local general = mark.all[mark.pos + bias]
    if general then
      local skills = Fk.generals[general]:getSkillNameList()
      player.room:handleAddLoseSkills(player, skills)
      player.room:setPlayerMark(player, "@rfenghou_3d17j__lanjiao", general)
    end
  end
})

lanjiao:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  late_refresh = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@rfenghou_3d17j__lanjiao") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local general = player:getMark("@rfenghou_3d17j__lanjiao")
    local skills = table.map(Fk.generals[general]:getSkillNameList(), function(s) return "-" .. s end)
    player.room:handleAddLoseSkills(player, skills)
    player.room:setPlayerMark(player, "@rfenghou_3d17j__lanjiao", 0)
  end
})

Fk:loadTranslationTable{
  ["rfenghou_3d17j__lanjiao"] = "揽娇",
  [":rfenghou_3d17j__lanjiao"] = "转换技，锁定技，游戏开始时，你从武将牌堆中随机抽取等量的女性武将牌代替你的每枚勾玉。每回合开始时，你于此回合内视为拥有离“神·董卓”①左侧②右侧最近的武将牌上的技能。<br>" ..
  "<a href=':programmer_rfenghou_3d17j__lanjiao'>实际上……？</a>",

  [":programmer_rfenghou_3d17j__lanjiao"] = "转换技，锁定技，游戏开始时，你随机抽取等于你体力上限的女性武将牌置于“娇”内；回合开始时，本回合内你视为拥有第X个“娇”上的技能。（X为你已损失的体力值①-1②+1）",

  ["@[rfenghou_3d17j__lanjiao]rfenghou_3d17j__lanjiao"] = "娇",
  ["@rfenghou_3d17j__lanjiao"] = "揽娇",
}

return lanjiao
